<template>
	<view class="content">
		<view class="logistics-box flexWrapNo"  @tap="goPage('/pages/shop/logistics?order_id='+order_id)" v-if="expressno">
			<image src="../../static/shop/logistics-icon.png" class="logistics-icon"></image>
			<view class="logistics-info">
				<view class="info-top flexWrap">
					<view>{{expressname||'--'}}（{{expressno||'--'}}）</view>
					<!-- <view class="status">配送中</view> -->
				</view>
				<!-- <view class="info-cont">
					<view class="info-item">
						卖家已发货 2023-11-21 11:31:11
					</view>
					<view class="info-item">
						到达成都中转站  2023-11-22 11:31:11
					</view>
					<view class="info-item">
						到达点点花园中驿站  2023-11-22 11:31:11
					</view>
				</view> -->
			</view>
		</view>
		<view class="address-box flexWrap">
			<view class="address-left flexWrapNo">
				<image src="../../static/shop/address-icon.png" class="address-icon"></image>
				<view class="address-info">
					<view class="address-item">收货人:{{orderInfo.receiver||'--'}}</view>
					<view class="address-item" @tap="makePhoneCall()">收货人手机号:{{orderInfo.mobile||'--'}}</view>
					<view class="address-item">收货人地址{{orderInfo.address||'--'}}</view>
				</view>
			</view>
		</view>
		<view class="shop-box">
			<view class="top-box flexWrap">
				<view class="date">{{createtime}}</view>
				<view class="status" v-if="orderInfo.orderstate==0&&orderInfo.paystate==0">待支付</view>
				<view class="status" v-if="orderInfo.orderstate==0&&orderInfo.paystate==1&&orderInfo.shippingstate==0">待发货</view>
				<view class="status" v-if="orderInfo.orderstate==0&&orderInfo.paystate==1&&orderInfo.shippingstate==1">待收货</view>
				<view class="status" v-if="orderInfo.orderstate==3&&orderInfo.paystate==1">已完成</view>
			</view>
			<view class="shop-cont">
				<view class="shop-item flexWrapNo" v-for="(item,index) in goodInfo" :key="index">
					<image :src="item.image" class="shop-img"></image>
					<view class="shop-info-box flexWarpColumn">
						<view class="info-box">
							<view>{{item.title||'--'}}</view>
							<view class="specs-box">{{item.attrdata||'默认'}} , x{{item.nums||'--'}}</view>
						</view>
						<view class="price">¥{{item.price||'--'}}</view>
					</view>
				</view>
			</view>
			<view class="total-box">
				共{{nums}}件 总额 <text class="price">¥{{orderInfo.amount||'--'}}</text>
			</view>
		</view>
		<view class="order-box">
			<view class="order-info">
				订单编号:{{orderInfo.order_sn}}
			</view>
			<view class="order-info">
				支付方式:微信支付
			</view>
			<view class="order-info">
				下单时间:{{createtime}}
			</view>
			<block v-if="orderInfo.shippingstate!=0">
				<view class="order-info">
					物流公司:{{orderInfo.expressname}}
				</view>
				<view class="order-info">
					快递单号: {{orderInfo.expressno}}
				</view>
				<view class="order-info" v-if="send_time">
					发货时间:{{send_time}}
				</view>
			</block>
			<view class="order-info" v-if="orderInfo.orderstate==0&&orderInfo.paystate==1&&orderInfo.shippingstate==0">
				成交时间:{{paytime}}
			</view>
		</view>
		<view class="bottom-box flexWarpCenterColumn" v-if="orderInfo.shippingstate==0">
			<view class="flexWrapNo input-item">
				是否自配:
				<switch style="margin-left: 30upx;transform: scale(.8);"></switch>
			</view>
			<view class="flexWrapNo input-item">
				快递公司:
				<view class="input-box flexWrapNo">
					<picker @change="bindPickerChange" :value="index" :range="shipperList" range-key="name">
						<view class="uni-input">{{shipperList[index].name}}</view>
					</picker>
					<text class="icon-more"></text>
				</view>
			</view>
			<view class="flexWrapNo input-item">
				快递单号:
				<view class="input-box">
					<input placeholder="请输入快递单号" placeholder-class="placeClass" v-model="expressno"/>
				</view>
			</view>
			<view class="define-btn" @tap="sendLogistics()">确定</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderId:"",
				orderInfo:{},
				goodInfo:{},
				createtime:"",
				paytime:"",
				nums:"",
				order_id:"",
				expressno:"",
				expressname:"",
				send_time:"",
				shipperList:[],
				index:0,
				expressnum:'',
				ordersn:""
			};
		},
		onLoad(ops) {
			this.orderId=ops.orderId
			this.getOrderInfo()
			// this.logistics();
			this.getShipperList();
		},
		methods:{
			bindPickerChange: function(e) {
				this.index = e.detail.value
				this.expressname=this.shipperList[this.index].name
				this.expressnum=this.shipperList[this.index].id
			},
			getOrderInfo(){
				this.$request.post(this.$api.orderNoteDeatils, {
					ordersn:this.orderId
				}, {
					token:true
				}).then(res => {
					if (res.code == 1) {
						let {
							data = {}
						} = res;
						this.orderInfo=data
						this.goodInfo=data.goods
						this.createtime=this.$tools.formatDate(data.createtime)
						this.paytime=this.$tools.formatDate(data.paytime)
						this.send_time=data.send_time?this.$tools.formatDate(data.send_time):""
						this.nums=this.goodInfo[0].nums
						this.order_id=data.id
						this.expressno=data.expressno
						this.expressname=data.expressname
						this.ordersn=data.order_sn
					}
				})
			},
			// 拨打电话
			makePhoneCall() {
				let that = this
				uni.makePhoneCall({
					phoneNumber:that.orderInfo.mobile
				})
			},
			logistics(){
				this.$request.post(this.$api.logistics, {
					ordersn:this.orderId
				}, {
					token:true
				}).then(res => {
					if (res.code == 1) {
						let {
							data = {}
						} = res;
					}
				})
			},
			getShipperList(){
				this.$request.post(this.$api.shipperList, {
					ordersn:this.orderId
				}, {
					token:true
				}).then(res => {
					if (res.code == 1) {
						let {
							data = {}
						} = res;
						this.shipperList=data
						this.expressname=this.shipperList[0].name
						this.expressnum=this.shipperList[0].id
					}
				})
			},
			sendLogistics(){
				this.$request.post(this.$api.sendLogistics, {
					ordersn:this.ordersn,
					order_id:this.orderId,
					expressname:this.expressname,
					expressno:this.expressno,
					expressnum:this.expressnum
				}, {
					token:true
				}).then(res => {
					if (res.code == 1) {
						let {
							data = {}
						} = res;
						this.getOrderInfo()
						// this.logistics();
						this.$tools.showToast('提交成功')
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.content{
		padding: 44upx 36upx;
		// padding-bottom: 200upx;
	}
	.logistics-box{
		background: #1D1C5C;
		border-radius: 16rpx;
		padding: 32upx 28upx;
		align-items: flex-start;
		.logistics-icon{
			width: 36upx;
			height: 32upx;
			margin-right: 24upx;
			flex: none;
		}
		.logistics-info{
			.info-top{
				font-size: 32rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				.status{
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #FF4646;
				}
			}
			.info-cont{
				margin-top: 12upx;
				.info-item{
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color:#8E8EAE;
					line-height: 40upx;
				}
			}
		}
	}
	.address-box{
		background: #1D1C5C;
		border-radius: 16rpx;
		padding: 32upx 28upx;
		margin-top: 20upx;
		.address-left{
			align-items: start;
			.address-icon{
				width: 34upx;
				height: 40upx;
				flex: none;
			}
			.address-info{
				margin-left: 26upx;
				.address-item{
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					line-height: 44upx;
				}
				.address-details{
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color:#8584A0;
					margin: 12upx 0;
				}
				.user-info{
					font-size: 24rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color:#8584A0;
				}
			}
		}
		.icon-more{
			border-color: #FFFFFF;
		}
	}
	.shop-box{
		background: #1D1C5C;
		border-radius: 16rpx;
		margin-top: 36upx;
		.top-box{
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #FFFFFF;
			padding: 32upx 28upx;
		}
		.shop-item{
			margin-bottom: 20upx;
			&:nth-last-of-type(1){
				margin-bottom: 0;
			}
		}
		.shop-cont{
			padding: 32upx 28upx;
			border-top: 1rpx solid #36355E;
			border-bottom: 1rpx solid #36355E;
			.shop-img{
				width: 164rpx;
				height: 164rpx;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				flex: none;
			}
			.shop-info-box{
				margin-left: 28upx;
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color:#FFFFFF;
				height: 164rpx;
				justify-content: space-between;
				.info-box{
					.specs-box{
						color: #8786A8;
						margin-top: 12upx;
					}
				}
			}
		}
		.total-box{
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color:#8786A8;
			line-height: 100upx;
			text-align: right;
			padding: 0 28upx;
			.price{
				color: #FFFFFF;
				margin-left: 24upx;
			}
		}
	}
	.order-box{
		margin-top: 20upx;
		padding: 32upx 0;
		.order-info{
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color:#82819B;
			margin-bottom: 20upx;
		}
	}
	.bottom-box{
		margin: auto;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		justify-content: center;
		.input-item{
			width: 100%;
			margin-bottom: 20upx;
		}
		.input-box{
			height: 80upx;
			background: rgba(255,255,255,.1);
			border-radius: 16upx;
			margin-left: 30upx;
			width: 380upx;
			input,picker{
				padding: 0 28upx;
				height: 80upx;
				line-height:80upx;
				font-size: 28upx;
				font-family: PingFang SC;
				font-weight: 500;
				color:rgba(255,255,255,.5);
				width: 90%;
			}
			.icon-more{
				border-color: #FFFFFF;
				margin-right: 10upx;
			}
			.placeClass{
				font-size: 28upx;
				font-family: PingFang SC;
				font-weight: 500;
				color:rgba(255,255,255,.5);
			}
		}
		.define-btn{
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			line-height: 80rpx;
			width: 282rpx;
			height: 80rpx;
			background: #26BCFD;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			text-align: center;
			margin-top: 30upx;
		}
	}
</style>
